#include "setting_ui.h"
#include <math.h>
#include "esp_log.h"
#include "lvgl.h"
#include "main_ui.h"
#include "md_languages.h"
#include "md_images.h"
#include "ui_setting.h"
#include "func_ui.h"

/* 字体声明 */
LV_FONT_DECLARE(myFont); // 声明自定义字体
LV_FONT_DECLARE(lv_font_montserrat_14);
static void refresh_settings_ui();
lv_obj_t *app_list = NULL;
// 全局变量记录当前设置界面
/*
* 必须使用两个变量，lv_obj_del传的是地址，如果使用一个变量，可能会导致删除的是新创建的界面
* lvgl在lv_timer_handler处理事件的时候，如果调完删除函数又调创建函数，在到lv_timer_handler，就会导致删除的是新创建的界面，导致界面显示异常
*/
static lv_obj_t *current_settings_screen = NULL;
static lv_obj_t *settings_screen_old = NULL;
static bool circular_scroll = true;         // 圆形滚动
static bool is_refresh_main_screen = false; // 标记刷新主界面
static bool is_author_right_slide = false;  //标志是否是在作者界面右滑的
lv_obj_t *author_screen = NULL;             ///作者界面
void exit_settings_ui(lv_obj_t * root)
{
    if (!root) {
        return;
    }
    if (is_refresh_main_screen) {
        is_refresh_main_screen = false;
        refresh_main_screen();
        set_ui_setting(NULL, true);
    } else {
        switch_to_main_screen();
    }
    lv_obj_del(root); //
}
// 手势事件回调
static void event_handler(lv_event_t *e)
{
    lv_event_code_t code = lv_event_get_code(e);

    if (code == LV_EVENT_GESTURE) {
        if (is_author_right_slide) // 作者界面右滑
        {
            is_author_right_slide = false;
            lv_obj_del(author_screen);
            refresh_settings_ui();
        } else { //退回主界面
            lv_indev_t *indev = lv_indev_get_act();
            if (!indev)
                return;

            lv_dir_t dir = lv_indev_get_gesture_dir(indev);

            if (dir == LV_DIR_RIGHT) {
                lv_obj_t *screen = lv_event_get_current_target(e);
                exit_settings_ui(screen);
            }
        }
    }
}

/**********************************************************************************************************/

static void lv_demo_smartwatch_scroll_event(lv_event_t *e)
{
    // 获取事件类型
    lv_event_code_t event_code = lv_event_get_code(e);

    // 只处理滚动事件，其他事件直接返回
    if (event_code != LV_EVENT_SCROLL)
        return;

    // 获取触发事件的滚动列表对象
    lv_obj_t *list = lv_event_get_target(e);
    if (!list)
        return;

    // 获取列表的坐标区域
    lv_area_t list_a;
    lv_obj_get_coords(list, &list_a);

    // 计算列表垂直中心点坐标
    lv_coord_t list_y_center = list_a.y1 + lv_area_get_height(&list_a) / 2;

    // 设置弧形滚动的半径（列表高度的60%）
    lv_coord_t r = lv_obj_get_height(list) * 6 / 10;

    // 获取列表中的子对象数量
    uint32_t child_cnt = lv_obj_get_child_cnt(list);

    // 遍历所有子对象
    for (uint32_t i = 0; i < child_cnt; i++) {
        lv_obj_t *child = lv_obj_get_child(list, i);
        if (!child)
            continue;

        // 确保对象是基础lv_obj类型（过滤非基础对象）
        if (!lv_obj_has_class(child, &lv_obj_class))
            continue;

        // 获取子对象的坐标区域
        lv_area_t child_a;
        lv_obj_get_coords(child, &child_a);

        // 计算子对象垂直中心点坐标
        lv_coord_t child_y_center = child_a.y1 + lv_area_get_height(&child_a) / 2;

        // 计算子对象与列表中心的垂直距离（绝对值）
        lv_coord_t diff_y = LV_ABS(child_y_center - list_y_center);

        // 计算子对象的水平偏移量（用于弧形效果）
        lv_coord_t x;
        if (diff_y >= r) {
            // 当距离超过半径时，使用最大偏移量（半径值）
            x = r;
        } else {
            // 应用圆形公式计算偏移：x = r - sqrt(r² - dy²)
            uint32_t x_sqr = (uint32_t)(r * r) - (uint32_t)(diff_y * diff_y);
            lv_sqrt_res_t res;            // 平方根计算结果结构体
            lv_sqrt(x_sqr, &res, 0x8000); // 计算平方根（使用Q15格式的定点数）
            x = r - res.i;                // 计算实际偏移值
        }

        // 安全更新子对象位置：
        // 1. 先删除现有的平移动画（避免冲突）
        lv_anim_del(child, (lv_anim_exec_xcb_t)lv_obj_set_style_translate_x);

        // 2. 设置新的水平偏移（根据circular_scroll标志决定是否启用弧形效果）
        lv_obj_set_style_translate_x(child, circular_scroll ? x : 0, LV_STATE_DEFAULT);
    }
}
// 刷新设置界面函数
static void refresh_settings_ui()
{
    settings_screen_old = current_settings_screen;

    // 创建新界面
    lv_obj_t *new_screen = create_settings_ui();
    if (new_screen) {
        // 加载新界面
        lv_scr_load(new_screen);
        // 删除旧界面
        lv_obj_del(settings_screen_old);
        settings_screen_old = NULL;
    }
}
// 语言下拉框回调
static void language_dd_event_cb(lv_event_t *e)
{
    lv_obj_t *dd = lv_event_get_target(e);
    uint16_t id = lv_dropdown_get_selected(dd);
    is_refresh_main_screen = true; // 标记刷新主界面

    set_screen_language(id, false);
    /*刷新界面*/
    refresh_settings_ui();
}

// 亮度滑动条回调
static void brightness_slider_event_cb(lv_event_t *e)
{
    lv_obj_t *slider = lv_event_get_target(e);
    int value = lv_slider_get_value(slider);
    set_screen_bright(value, false);
}

// 屏幕颜色下拉框回调
static void color_dd_event_cb(lv_event_t *e)
{
    lv_obj_t *dd = lv_event_get_target(e);
    uint16_t id = lv_dropdown_get_selected(dd);
    is_refresh_main_screen = true; // 标记刷新主界面

    set_screen_color(id, false);
    /*刷新界面*/
    //load_func_ui(FUNC_SYSTEM_SETTINGS);
    // lv_obj_t *screen = lv_obj_get_parent(app_list);
    // if (screen)
    //     lv_obj_del(screen); // 异步删除避免在事件处理中删除对象
    refresh_settings_ui();
}

// 语音控制开关回调
static void voice_switch_event_cb(lv_event_t *e)
{
    lv_obj_t *sw = lv_event_get_target(e);
    bool state = lv_obj_has_state(sw, LV_STATE_CHECKED);
    //语音控制开关状态改变
    set_voice_control(state, false);
    is_refresh_main_screen = true; // 标记刷新主界面
}
// 截图控制开关回调
static void screenshot_switch_event_cb(lv_event_t *e)
{
    lv_obj_t *sw = lv_event_get_target(e);
    bool state = lv_obj_has_state(sw, LV_STATE_CHECKED);
    //语音控制开关状态改变
    set_screenshot_control(state, false);
    is_refresh_main_screen = true; // 标记刷新主界面
}
// 恢复出厂设置确认对话框回调
static void factory_reset_confirm_cb(lv_event_t *e)
{
    lv_obj_t *msgbox = lv_event_get_current_target(e);
    uint16_t btn_id = lv_msgbox_get_active_btn(msgbox);

    // 1. 获取关闭按钮对象
    lv_obj_t *close_btn = lv_msgbox_get_close_btn(msgbox);

    // 2. 发送点击事件
    if (close_btn) {
        lv_event_send(close_btn, LV_EVENT_CLICKED, NULL);
    }

    if (btn_id == 0) { // 用户点击了"确认"
        // 执行恢复出厂设置
        ui_setting_load_default(false);
    }
    refresh_settings_ui();
}
// 恢复出厂设置开关回调
static void factory_reset_event_cb(lv_event_t *e)
{
    lv_obj_t *sw = lv_event_get_target(e);
    bool state = lv_obj_has_state(sw, LV_STATE_CHECKED);

    if (state) // 开关被打开
    {
        lv_obj_clear_state(sw, LV_STATE_CHECKED);
        //隐藏
        //lv_obj_add_flag(current_settings_screen, LV_OBJ_FLAG_HIDDEN);
        // 创建确认对话框
        static const char *btns[3];
        btns[0] = get_func_txt_data(FUNC_SYSTEM_SETTINGS, SETTINGS_CONFIRM_NUM);
        btns[1] = get_func_txt_data(FUNC_SYSTEM_SETTINGS, SETTINGS_CANCEL_NUM);
        btns[2] = "";

        lv_obj_t *msgbox = lv_msgbox_create(NULL,
                                            get_func_txt_data(FUNC_SYSTEM_SETTINGS, SETTINGS_RESET_TITLE_NUM),
                                            get_func_txt_data(FUNC_SYSTEM_SETTINGS, SETTINGS_RESET_MSG_NUM),
                                            btns, true);

        // 设置对话框样式
        lv_obj_set_style_bg_color(msgbox, lv_color_hex(get_screen_color_val()), LV_PART_MAIN);
        lv_obj_set_style_text_color(msgbox, get_btn_font_color(), LV_PART_MAIN);
        lv_obj_set_style_text_font(msgbox, &myFont, LV_PART_MAIN);

        lv_obj_t *btnm = lv_msgbox_get_btns(msgbox);
        if (btnm) {
            // 设置按钮之间的水平间距（
            lv_obj_set_style_pad_column(btnm, 30, LV_PART_MAIN);

            // 设置按钮的内边距（，使按钮更大）
            lv_obj_set_style_pad_hor(btnm, 8, LV_PART_ITEMS);
        }

        // 设置提示文字样式 - 红色
        lv_obj_t *txt = lv_msgbox_get_text(msgbox);
        if (txt) {
            lv_obj_set_style_text_color(txt, lv_color_hex(0xFF0000), LV_PART_MAIN); // 红色提示文字
        }
        // 获取关闭按钮对象
        lv_obj_t *close_btn = lv_msgbox_get_close_btn(msgbox);

        // 方法1：设置包含关闭图标字符的字体
        lv_obj_set_style_text_font(close_btn, &lv_font_montserrat_14, LV_PART_MAIN);

        // 调整关闭按钮大小以确保图标可见
        lv_obj_set_size(close_btn, 32, 32);

        // 设置文本颜色
        lv_obj_set_style_text_color(close_btn, get_btn_font_color(), LV_PART_MAIN);
        // 添加事件回调，传递开关对象作为用户数据
        lv_obj_add_event_cb(msgbox, factory_reset_confirm_cb, LV_EVENT_VALUE_CHANGED, NULL);

        // 居中显示对话框
        lv_obj_center(msgbox);
    }
}
void create_author_info_panel(lv_obj_t *parent)
{
    // 创建作者信息容器
    author_screen = lv_obj_create(parent);
    lv_obj_set_size(author_screen, lv_pct(100), lv_pct(100));
    lv_obj_center(author_screen);
    lv_obj_set_style_bg_color(author_screen, lv_color_white(), 0);
    lv_obj_set_style_border_width(author_screen, 0, 0);
    lv_obj_set_style_radius(author_screen, 10, 0);
    lv_obj_set_flex_flow(author_screen, LV_FLEX_FLOW_COLUMN); // 启用列布局
    lv_obj_set_style_pad_all(author_screen, 20, 0);           // 设置内边距

    // 关键修复：设置Flex容器对齐方式
    lv_obj_set_flex_align(
        author_screen,
        LV_FLEX_ALIGN_CENTER,  // 垂直方向对齐方式
        LV_FLEX_ALIGN_CENTER,  // 水平方向对齐方式
        LV_FLEX_ALIGN_CENTER); // 交叉轴对齐方式

    // 添加顶部间距容器
    lv_obj_t *top_spacer = lv_obj_create(author_screen);
    lv_obj_set_size(top_spacer, lv_pct(100), 30);          // 30像素顶部间距
    lv_obj_remove_style_all(top_spacer);                   // 移除所有样式
    lv_obj_set_style_bg_opa(top_spacer, LV_OPA_TRANSP, 0); // 完全透明
    // 作者名称
    lv_obj_t *author_label_1 = lv_label_create(author_screen);
    lv_label_set_text(author_label_1, "作者 :  米多");
    lv_obj_set_style_text_font(author_label_1, &myFont, 0);
    lv_obj_set_style_text_color(author_label_1, lv_color_hex(0x555555FF), 0); //
    lv_obj_set_style_pad_bottom(author_label_1, 15, 0);                       // 标签间间距
    lv_obj_align(author_label_1, LV_ALIGN_TOP_MID, 0, 20);                    // 顶部居中，顶边距10px
    // 版本信息
    lv_obj_t *author_label_2 = lv_label_create(author_screen);
    lv_label_set_text(author_label_2, "版本号 :  V0.0");
    lv_obj_set_style_text_font(author_label_2, &myFont, 0);
    lv_obj_set_style_pad_bottom(author_label_2, 15, 0); // 标签间间距

    // QQ号
    lv_obj_t *author_label_3 = lv_label_create(author_screen);
    lv_label_set_text(author_label_3, "QQ :  2650712577");
    lv_obj_set_style_text_font(author_label_3, &myFont, 0);
    lv_obj_set_style_pad_bottom(author_label_3, 40, 0); // 到二维码的间距

    // 二维码
    lv_obj_t *author_qrcode_1 = lv_qrcode_create(author_screen, 120,
                                                 lv_color_hex(0x2C3224), lv_color_hex(0xffffff));

    const char *screen_writer_qrcode_1_data = "https://b23.tv/mFImOGy";
    lv_qrcode_update(author_qrcode_1,
                     screen_writer_qrcode_1_data,
                     strlen(screen_writer_qrcode_1_data));

    // 二维码说明文字
    lv_obj_t *qr_label = lv_label_create(author_screen);
    lv_label_set_text(qr_label, "扫码联系作者");
    lv_obj_set_style_text_font(qr_label, &myFont, 0);
    lv_obj_set_style_text_color(qr_label, lv_color_hex(0x777777FF), 0); // 添加透明度
    lv_obj_set_style_pad_top(qr_label, 10, 0);                          // 文字与二维码间距
}
// 关于作者信息事件回调
static void author_info_event_cb(lv_event_t *e)
{
    lv_obj_t *label = lv_event_get_target(e);
    lv_event_code_t code = lv_event_get_code(e);
    if (LV_EVENT_CLICKED == code) // 点击事件
    {
        is_author_right_slide = true;
        create_author_info_panel(lv_scr_act());
    }
}
static void add_setting_item(const char *setting_name, int index, char *icon_symbol)
{
    lv_obj_t *panel = lv_obj_create(app_list);
    if (!panel)
        return;

    // 设置面板大小并去除所有边距
    lv_obj_set_size(panel, lv_pct(100), 64);
    lv_obj_clear_flag(panel, LV_OBJ_FLAG_SCROLLABLE);

    // 面板样式 - 去除所有边距和内边距
    lv_obj_set_style_pad_all(panel, 0, LV_PART_MAIN);
    // 修复后（正确）

    // lv_obj_set_style_margin_top(panel, 0, LV_PART_MAIN);
    // lv_obj_set_style_margin_bottom(panel, 0, LV_PART_MAIN);
    // lv_obj_set_style_margin_left(panel, 0, LV_PART_MAIN);
    // lv_obj_set_style_margin_right(panel, 0, LV_PART_MAIN);
    lv_obj_set_style_bg_opa(panel, LV_OPA_COVER, 0);
    lv_obj_set_style_bg_color(panel, lv_color_hex(get_screen_color_val()), 0);
    //lv_obj_set_style_border_color(panel, lv_color_white(), 0);
    lv_obj_set_style_border_opa(panel, LV_OPA_COVER, 0);
    lv_obj_set_style_border_width(panel, 1, 0);
    lv_obj_set_style_border_side(panel, LV_BORDER_SIDE_BOTTOM, 0);
    lv_obj_set_style_radius(panel, 0, 0);
    lv_obj_set_style_text_font(panel, &myFont, 0);

    // 创建图标 - 使用图片控件
    lv_obj_t *icon = lv_img_create(panel);
    lv_img_set_src(icon, icon_symbol);           // 设置图片源
    lv_obj_set_size(icon, 32, 32);               // 设置图标大小
    lv_obj_align(icon, LV_ALIGN_LEFT_MID, 5, 0); // 左侧对齐，左边距5px

    // 设置名称标签 - 紧挨着图标
    lv_obj_t *label = lv_label_create(panel);
    if (label) {
        lv_obj_set_style_text_color(label, get_btn_font_color(), 0);
        lv_label_set_text(label, setting_name);
        lv_obj_align_to(label, icon, LV_ALIGN_OUT_RIGHT_MID, 7, 0); // 图标右侧10px
    }

    // 根据索引创建不同类型的控件
    switch (index) {
        case 0: { // 语言下拉框
            lv_obj_t *dd = lv_dropdown_create(panel);
            lv_dropdown_set_options(dd, "English\n中文");
            lv_obj_set_width(dd, 100);
            lv_obj_align(dd, LV_ALIGN_RIGHT_MID, -10, 0); // 右侧对齐，右边距5px
            lv_obj_add_event_cb(dd, language_dd_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
            // 设置默认选中的语言
            lv_dropdown_set_selected(dd, get_screen_language());
            break;
        }
        case 1: { // 亮度滑动条
            lv_obj_t *slider = lv_slider_create(panel);
            lv_slider_set_range(slider, 0, 100);
            lv_slider_set_value(slider, get_screen_bright(), LV_ANIM_OFF);
            lv_obj_set_width(slider, 100);
            lv_obj_align(slider, LV_ALIGN_RIGHT_MID, -10, 0); // 右侧对齐，右边距5px
            lv_obj_add_event_cb(slider, brightness_slider_event_cb, LV_EVENT_VALUE_CHANGED, NULL);

            // // 添加亮度值标签
            // lv_obj_t *value_label = lv_label_create(panel);
            // lv_label_set_text_fmt(value_label, "%d%%", 80);
            // lv_obj_align_to(value_label, slider, LV_ALIGN_OUT_RIGHT_MID, 5, 0);
            break;
        }
        case 2: { // 屏幕颜色下拉框
            lv_obj_t *dd = lv_dropdown_create(panel);
            lv_dropdown_set_options(dd, get_func_txt_data(FUNC_SYSTEM_SETTINGS, SETTINGS_BRIGHT_TYPE_NUM));
            lv_obj_set_width(dd, 100);
            lv_obj_align(dd, LV_ALIGN_RIGHT_MID, -10, 0); // 右侧对齐，右边距5px
                                                          // 设置默认选中的语言
            lv_dropdown_set_selected(dd, get_screen_color());
            lv_obj_add_event_cb(dd, color_dd_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
            break;
        }
        case 3: { // 语音控制开关
            lv_obj_t *sw = lv_switch_create(panel);
            lv_obj_align(sw, LV_ALIGN_RIGHT_MID, -10, 0); // 右侧对齐，右边距5px
            //lv_obj_add_state(sw, LV_STATE_CHECKED);      // 默认开启
            lv_obj_add_state(sw, get_voice_control()); //
            lv_obj_add_event_cb(sw, voice_switch_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
            break;
        }
        case 4: { // 截图控制开关
            lv_obj_t *sw = lv_switch_create(panel);
            lv_obj_align(sw, LV_ALIGN_RIGHT_MID, -10, 0); // 右侧对齐，右边距5px
            //lv_obj_add_state(sw, LV_STATE_CHECKED);      // 默认开启
            lv_obj_add_state(sw, get_screenshot_control()); //
            lv_obj_add_event_cb(sw, screenshot_switch_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
            break;
        }
        case 5: { // 恢复出厂设置开关
            lv_obj_t *sw = lv_switch_create(panel);
            lv_obj_align(sw, LV_ALIGN_RIGHT_MID, -10, 0); // 右侧对齐，右边距5px
            lv_obj_add_state(sw, LV_STATE_DEFAULT);       // 默认开启
            lv_obj_add_event_cb(sw, factory_reset_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
            break;
        }
        case 6: { // 作者信息
            // 创建图标 - 使用图片控件
            lv_obj_t *image = lv_img_create(panel);
            lv_obj_align(image, LV_ALIGN_RIGHT_MID, -10, 0);                                            // 右侧对齐，右边距5px
            lv_obj_add_flag(image, LV_OBJ_FLAG_CLICKABLE);                                              // 设置控件为可点击
            lv_img_set_src(image, get_func_image_data(FUNC_SYSTEM_SETTINGS, SETTINGS_AUTHOR_ENTR_NUM)); // 设置图片源
            lv_obj_set_size(image, 32, 32);                                                             // 设置图标大小
            lv_obj_add_event_cb(image, author_info_event_cb, LV_EVENT_ALL, NULL);
            break;
        }
    }
}
static lv_obj_t *root;
/* 
 * @ brief:创建设置界面
*/
lv_obj_t *
create_settings_ui(void)
{
   root = lv_obj_create(NULL);
    if (!root)
        return NULL;
    
    lv_obj_set_size(root, LV_PCT(100), LV_PCT(100));
    // lv_obj_set_style_bg_color(root, lv_color_black(), 0);
    uint32_t color = get_screen_color_val();
    lv_obj_set_style_bg_color(root, lv_color_hex(color), 0);
    lv_obj_clear_flag(root, LV_OBJ_FLAG_SCROLLABLE);

    // 使根对象可点击以接收手势事件
    lv_obj_add_flag(root, LV_OBJ_FLAG_CLICKABLE);
    lv_obj_add_event_cb(root, event_handler, LV_EVENT_GESTURE, root);

    /************************************************************************/
    app_list = lv_obj_create(root);
    if (!app_list) {
        lv_obj_del(root);
        return NULL;
    }
    lv_obj_set_style_bg_color(app_list, lv_color_hex(color), 0);
    lv_obj_set_size(app_list, lv_pct(100), lv_pct(100));
    lv_obj_set_scroll_dir(app_list, LV_DIR_VER);
    lv_obj_set_scrollbar_mode(app_list, LV_SCROLLBAR_MODE_OFF);
    lv_obj_set_flex_flow(app_list, LV_FLEX_FLOW_COLUMN);
    lv_obj_set_flex_align(app_list, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);

    // 允许事件冒泡
    lv_obj_add_flag(app_list, LV_OBJ_FLAG_GESTURE_BUBBLE);
    lv_obj_clear_flag(app_list, LV_OBJ_FLAG_CLICKABLE);

    // 列表样式
    lv_obj_set_style_bg_opa(app_list, LV_OPA_COVER, 0);
    // lv_obj_set_style_bg_color(app_list, lv_color_hex(get_screen_color_val()), 0);
    lv_obj_set_style_pad_top(app_list, 20, 0);    // 减少顶部内边距
    lv_obj_set_style_pad_bottom(app_list, 20, 0); // 减少底部内边距
    lv_obj_set_style_border_width(app_list, 0, 0);

    // 添加设置项
    add_setting_item(get_func_txt_data(FUNC_SYSTEM_SETTINGS, SETTINGS_LANG_NUM), 0, get_func_image_data(FUNC_SYSTEM_SETTINGS, SETTINGS_LANG_NUM));
    add_setting_item(get_func_txt_data(FUNC_SYSTEM_SETTINGS, SETTINGS_BRIGHT_NUM), 1, get_func_image_data(FUNC_SYSTEM_SETTINGS, SETTINGS_BRIGHT_NUM));
    add_setting_item(get_func_txt_data(FUNC_SYSTEM_SETTINGS, SETTINGS_SCREEN_COLOR_NUM), 2, get_func_image_data(FUNC_SYSTEM_SETTINGS, SETTINGS_SCREEN_COLOR_NUM));
    add_setting_item(get_func_txt_data(FUNC_SYSTEM_SETTINGS, SETTINGS_VOICE_CONTROL_NUM), 3, get_func_image_data(FUNC_SYSTEM_SETTINGS, SETTINGS_VOICE_CONTROL_NUM));
    add_setting_item(get_func_txt_data(FUNC_SYSTEM_SETTINGS, SETTINGS_SCREENSHOT_CONTROL_NUM), 4, get_func_image_data(FUNC_SYSTEM_SETTINGS, SETTINGS_SCREENSHOT_CONTROL_NUM));
    add_setting_item(get_func_txt_data(FUNC_SYSTEM_SETTINGS, SETTINGS_FACTORY_RESET_NUM), 5, get_func_image_data(FUNC_SYSTEM_SETTINGS, SETTINGS_FACTORY_RESET_NUM));
    add_setting_item(get_func_txt_data(FUNC_SYSTEM_SETTINGS, SETTINGS_AUTHOR_NUM), 6, get_func_image_data(FUNC_SYSTEM_SETTINGS, SETTINGS_AUTHOR_NUM));
    lv_obj_add_event_cb(app_list, lv_demo_smartwatch_scroll_event, LV_EVENT_SCROLL, NULL);

    // 设置滚动捕捉
    lv_obj_set_scroll_snap_y(app_list, LV_SCROLL_SNAP_CENTER);
    lv_obj_set_style_max_height(app_list, LV_PCT(90), 0);
    // 记录当前设置界面

    current_settings_screen = root;

    return root;
}